package cn.onlineclass.service;


import cn.onlineclass.dao.OResourceMapper;
import cn.onlineclass.entity.OResource;
import cn.onlineclass.util.AjaxPage;
import cn.onlineclass.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class resourceService {
    private static Logger Log = LoggerFactory.getLogger(resourceService.class);
    public static final resourceService TYPE = new resourceService();

    public int add(OResource a){
        SqlSession s= MybatisUtil.get();
        try {
            OResourceMapper mapper = s.getMapper(OResourceMapper.class);
            return mapper.add(a);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public AjaxPage search(int pageNo, int pageSize, boolean inuse, String majorid){
        SqlSession s = MybatisUtil.get();
        OResourceMapper mapper = s.getMapper(OResourceMapper.class);
        try {
            List<OResource> products = mapper.search(pageNo, 10,inuse,majorid );
            int total = mapper.searchTotal(inuse,majorid);
            return new AjaxPage(products, total, pageNo, pageSize);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }


    public int del(OResource t){
        SqlSession s = MybatisUtil.get();
        try {
            OResourceMapper mapper = s.getMapper(OResourceMapper.class);
            return mapper.del(t);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public int update(OResource p){
        SqlSession s = MybatisUtil.get();
        try {
            OResourceMapper mapper = s.getMapper(OResourceMapper.class);
            return mapper.update(p);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }
    public OResource get(long id){
        SqlSession s = MybatisUtil.get();
        try {
            OResourceMapper mapper = s.getMapper(OResourceMapper.class);
            return mapper.get(id);
        }finally {
            MybatisUtil.closeSession(s);
        }
    }

    private class MyBatisUtil {
    }
}
